function _getKursByDate(date, percent, type)
{
	var kurs = null;
	var arr_date = date.split("-");
	var d = Number(arr_date[2]);
	var m = Number(arr_date[1]);
	var y = Number(arr_date[0]);
	while(!kurs)
	{
		var key = _dateToDb(y + "-" + m + "-" + d);
		if(key < '2011-01-01') break;
		if(kurses[key])
		{
			if(kurses[key][percent])
			{
				kurs = kurses[key][percent][type];
				break;
			}
		}
		if(d > 1)
		{
			d--;
			continue;
		}
		if(m > 1)
		{
			m--;
			d = 31;
			continue;
		}
		y--;
		m = 12;
		d = 31;
	}
	return kurs;
}

function _dateToDb(date)
{
	var arr_date = date.split("-");
	var d = Number(arr_date[2]);
	var m = Number(arr_date[1]);
	var y = Number(arr_date[0]);
	var d_str = (d < 10 ? "0" : '') + d;
	var m_str = (m < 10 ? "0" : '') + m;
	return y + "-" + m_str + "-" + d_str;
}

function trim( str, charlist ) {	
	// Strip whitespace (or other characters) from the beginning and end of a string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: mdsjack (http://www.mdsjack.bo.it)
	// +   improved by: Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev)
	// +	  input by: Erkekjetter
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
	var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g');
	return str.replace(re, '');
}


function openPop(ml)
{
	document.getElementById('popbg').style.display = 'block';
	document.getElementById('pop').style.display = 'block';
	document.getElementById('pop_close').style.display = 'block';
	document.getElementById('pop_close').style.marginLeft = ml + "px";
}

function closePop()
{
	document.getElementById('popbg').style.display = 'none';
	document.getElementById('pop_close').style.display = 'none';
	var pop = document.getElementById('pop');
	pop.style.display = 'none';
	pop.innerHTML = '';
}

function openLoading()
{
	document.getElementById('popbg').style.display = 'block';
	document.getElementById('pop_loading').style.display = 'block';
}

function closeLoading()
{
	document.getElementById('popbg').style.display = 'none';
	document.getElementById('pop_loading').style.display = 'none';
}

function openVersion()
{
	openPop(330);
	var pop = document.getElementById('pop');
	pop.style.width = '600px';
	pop.style.marginLeft = '-330px';
	var frame = document.createElement('IFRAME')
	frame.width = 600;
	frame.height = 450;
	frame.frameborder = 0;
	frame.src = base_url + 'info/version_small/';
	frame.style.border = 'none';
	pop.appendChild(frame);
}


function getSaleOperId()
{
	var f = document.getElementById('f');
	var oper_id = null;
	if(f.oper_id.value != undefined) // один вид мавро
	{
		if(f.oper_id.checked)
		{
			oper_id = f.oper_id.value;
		}
	}
	else // несколько видов мавро
	{
		for(var i = 0; i < f.oper_id.length; i++)
		{
			if(f.oper_id[i].checked)
			{
				oper_id = f.oper_id[i].value;
				break;
			}
		}
	}
	return oper_id;
}

function getNumber(n)
{
	return Number(n.replace(",", "."));
}

inArray = Array.prototype.indexOf ?
    function (arr, val) {
        return arr.indexOf(val) != -1
    } :
    function (arr, val) {
        var i = arr.length
        while (i--) {
            if (a[i] === val) return true
        }
        return false
    }

function openFilter()
{
	var f = document.getElementById('filter');
	f.style.display = f.style.display == 'none' ? '' : 'none';
}
